import _ from 'lodash';

type IOptionType = {
  label: string;
  value: string | number;
};

/**
 * 步骤1
 */

// 获取价差
const priceSpreadSourceOptions = (marketId: string) => {
  const arr: any[] = [
    { label: '天机预测', value: 'tianji' },
    { label: '历史统计', value: 'history' },
  ];

  if (marketId !== 'PHBSD' && marketId !== 'PHBSX') {
    return [arr[1]];
  }

  if (marketId === 'PHBSD') {
    return [arr[0]];
  }

  return arr;
};

const priceSpreadValueOptions: IOptionType[] = [
  { label: '均值', value: 1 },
  { label: '最小值', value: 2 },
  { label: 'Q1', value: 3 },
  { label: '中位数', value: 4 },
  { label: 'Q3', value: 5 },
  { label: '最大值', value: 6 },
];

const smoothOptions: IOptionType[] = [
  { label: '不平滑', value: 'none' },
  { label: 'MODEL1', value: 'kalman' },
  { label: 'MODEL2', value: 'gaussian' },
];

const priceDiffBaseOptions = {
  grid: [
    {
      top: 28,
      left: 46,
      right: 30,
      height: '38.0%',
      bottom: 20,
    },
    {
      left: 46,
      right: 46,
      top: '66.4%',
      height: '27.4%',
      bottom: 28,
    },
  ],
  axisPointer: {
    link: [
      {
        xAxisIndex: 'all',
      },
    ],
    lineStyle: {
      color: '#4e5154',
      type: 'solid',
    },
  },
  tooltip: {
    textStyle: {
      fontSize: 12,
    },
  },
  legend: {
    left: '28%',
    top: 'bottom',
    itemGap: 20,
    itemWidth: 15,
    itemHeight: 8,
    textStyle: {
      color: '#a7a8a9',
      fontSize: 12,
    },
    data: [
      {
        name: '现货日前价预测',
        itemStyle: {
          opacity: 1,
          borderWidth: 1,
        },
      },
      {
        name: '现货实时价预测',
        itemStyle: {
          opacity: 1,
          borderWidth: 1,
        },
      },
      {
        name: '现货实时日前价差',
        itemStyle: {
          opacity: 1,
          borderWidth: 1,
        },
      },
      {
        name: '价差置信度',
      },
    ],
    inactiveBorderWidth: 'inherit',
  },
  toolbox: {
    show: false,
  },
  yAxis: [
    {
      type: 'value',
      name: '元/MWh',
      gridIndex: 0,
      splitNumber: 5,
      position: 'left',
      axisLine: {
        show: false,
      },
      nameTextStyle: {
        color: '#7a7d7f',
      },
      axisTick: {
        alignWithLabel: true,
        length: 4,
        lineStyle: {
          color: 'rgba(78, 81, 84, 0.5)',
        },
      },
      axisLabel: {
        color: '#7a7d7f',
        fontSize: 12,
        margin: 8,
        height: 12,
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'solid',
          color: 'rgba(78, 81, 84, 0.5)',
        },
      },
    },
    {
      type: 'value',
      gridIndex: 1,
      position: 'left',
      splitNumber: 5,
      axisLine: {
        show: false,
      },
      nameTextStyle: {
        color: '#7a7d7f',
      },
      axisTick: {
        alignWithLabel: true,
        length: 4,
        lineStyle: {
          color: 'rgba(78, 81, 84, 0.5)',
        },
      },
      axisLabel: {
        color: '#7a7d7f',
        fontSize: 12,
        margin: 8,
        height: 12,
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'solid',
          color: 'rgba(78, 81, 84, 0.5)',
        },
      },
    },
    {
      type: 'value',
      gridIndex: 1,
      splitNumber: 5,
      name: '置信度/%',
      position: 'right',
      axisLine: {
        show: false,
      },
      nameTextStyle: {
        color: '#7a7d7f',
      },
      axisTick: {
        alignWithLabel: true,
        length: 4,
        lineStyle: {
          color: 'rgba(78, 81, 84, 0.5)',
        },
      },
      axisLabel: {
        color: '#7a7d7f',
        fontSize: 12,
        margin: 8,
        height: 12,
      },
      splitLine: {
        show: false,
        lineStyle: {
          type: 'solid',
          color: 'rgba(78, 81, 84, 0.5)',
        },
      },
    },
  ],
};

const powerAdjustBaseOptions = {
  grid: {
    top: 28,
    left: 46,
    bottom: 45,
    right: 30,
  },
  tooltip: {
    textStyle: {
      fontSize: 12,
    },
  },
  axisPointer: {
    link: [
      {
        xAxisIndex: 'all',
      },
    ],
    lineStyle: {
      color: '#4e5154',
      type: 'solid',
    },
  },
  legend: {
    top: 'bottom',
    itemGap: 20,
    itemWidth: 15,
    itemHeight: 8,
    textStyle: {
      color: '#a7a8a9',
      fontSize: 12,
    },
    inactiveBorderWidth: 'inherit',
  },
  yAxis: [
    {
      type: 'value',
      name: 'MW',
      axisLine: {
        show: false,
      },
      nameTextStyle: {
        color: '#7a7d7f',
        fontSize: 12,
      },
      axisTick: {
        alignWithLabel: true,
        length: 4,
        lineStyle: {
          color: 'rgba(78, 81, 84, 0.5)',
        },
      },
    },
    {
      type: 'value',
      name: '%',
      axisLine: {
        show: false,
      },
      nameTextStyle: {
        color: '#7a7d7f',
        fontSize: 12,
      },
      axisTick: {
        alignWithLabel: true,
        length: 4,
        lineStyle: {
          color: 'rgba(78, 81, 84, 0.5)',
        },
      },
    },
  ],
};

export const getBaseKeys = (data = {}) => {
  return Object.keys(data)
    .filter((i) => i.includes('Values'))
    .map((i) => i.replace('Values', ''));
};

export const getXAxisData = (date: string, data: any[]) => {
  return (
    data?.map((i) => {
      return `${date} ${i}`;
    }) || []
  );
};

export {
  priceSpreadSourceOptions,
  priceSpreadValueOptions,
  smoothOptions,
  priceDiffBaseOptions,
  powerAdjustBaseOptions,
};
